<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{$Assets}layui/css/layui.css">
    <script src="{$Assets}aikenjs/jquery.js"></script>
    <style type="text/css">
        .layui-input-block{
            margin-right: 50px;   
        }
    </style>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend></legend>
</fieldset>

<form class="layui-form" action="">

	<input type="hidden" name="id" value="{$info.id}">

  <div class="layui-form-item">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="required" value="{$info.title}" autocomplete="off"  placeholder="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">作者</label>
    <div class="layui-input-inline">
      <input type="text" name="issue" placeholder="" autocomplete="off" class="layui-input" value="{$info.issue}">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">价格</label>
    <div class="layui-input-inline">
      <input type="text" name="pay" placeholder="" autocomplete="off" class="layui-input" value="{$info.pay}">
    </div>
  </div>

  <div class="layui-form-item">
        <label class="layui-form-label">所属栏目</label>
          <div class="layui-input-inline" style="color: #000;width: 400px;">
            <select name="class" lay-verify="required">
              <option value=""></option>
              {volist name="column" id="vo" }
                  <option value="{$vo.id}" 
                    {if condition="$info.class == $vo.id"} selected="" {/if}
                  ><?php echo str_repeat("&#8195;", $vo['level']);?>{if condition="$vo.level !=1"}└{/if}{$vo.classname}</option>
              {/volist}
            </select>
          </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">产品图片</label>
    <div class="layui-input-inline">
      <button type="button" class="layui-btn" id="addimg">上传</button><p style="color: #999;font-size: 12px;display: inline-block;margin-top: 15px;">已上传<span id="uploadimg" style="color: #f00;">{$info.num}</span>张图片</p>
    </div>
  </div>
  <input type="hidden" name="delimg" value="">
  <input type="hidden" name="imgcount" value="{$info.num}" id="imgconunt">
  <div class="layui-upload" style="margin-left: 110px;margin-right: 50px;">
      <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
          <span style="color: #999;">(点击图片即可删除)</span>
          <div class="layui-upload-list" id="imglist">
          
              {volist name="$info.imglist" id="vo"}
                  <img src="{$vo}" class="layui-upload-img" style="width:200px;" id="src{$i}"  onclick="del({$i})">
                  <input type="hidden" name="imglist{$i}" value="{$vo}" id="input{$i}">
              {/volist}
          </div>
      </blockquote>
  </div>



      

  <div class="layui-form-item">
    <label class="layui-form-label">详细内容</label>
    <div class="layui-input-block">
      <textarea class="layui-textarea" id="LAY_demo2" style="display: none">{$info.content}</textarea>
    </div>
  </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="editpro">提交</button>
        </div>
    </div>

</form>



<script src="{$Assets}layui/layui.js?t=1515376178709"></script>
<script>
    layui.use(['form', 'layedit', 'laydate','upload'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,upload = layui.upload
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$ = layui.jquery;

        //
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //
        var index = layedit.build('LAY_demo2');

        //
        form.verify({
            
        });

          //
        form.on('submit(editpro)', function(data){

          var datas=JSON.stringify(data.field);
          var content=layedit.getContent(index);
          var iframe = parent.layer.getFrameIndex(window.name);


                  $.ajax({
                        type:"POST",
                        url: "{:url('product/editprosave')}",
                        data:{data:datas,content:content},
                        dataType:"json",

                        success:function(ret_datas){
                            if(ret_datas==1){
                                layer.msg('修改成功');
                                setTimeout(function(){
                                  parent.layer.close(iframe);
                                  parent.location.reload();
                                },"1000");
                            }else if(ret_datas==99){
                                layer.msg('修改异常');
                            }else{
                                layer.msg(ret_datas);
                            }
                        }
                    });

          return false;
        });


  //
  upload.render({
    elem: '#addimg'
    ,url: "{:url('product/productimgsave')}"
    ,multiple: true
    ,before: function(obj){
      //ie8
      obj.preview(function(index, file, result){
        var numimg=document.getElementById("uploadimg").innerText;
        numimg=numimg*1+1*1;
        $('#imglist').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="width:200px;" id="src'+numimg+'" onclick="del('+numimg+')">');
        
      });
    }
    ,done: function(res){
      //
      //layer.msg(res.data.src);

      var count=document.getElementById("uploadimg");
        count.innerText=count.innerText*1+1*1;
        var num=document.getElementById("uploadimg").innerText;
        $("#imgconunt").attr("value",num);
        $('#imglist').append('<input type="hidden" name="imglist'+num+'" value="'+res.data.src+'" id="input'+num+'">');
    }
  });
	

    });
</script>
<script type="text/javascript">
    function del(id){
    	var obj = document.getElementById("src"+id);
    var impParent = obj.parentNode;//img
    impParent.removeChild(obj);//img


		var ob = document.getElementById("input"+id);
		ob.remove();

    }
</script>
{include file="public/footer"/}
</body>
</html>
